package com.kaigejava.kgblog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kaigejava.kgblog.dao.auto.tStudentMapper;
import com.kaigejava.kgblog.model.auto.tStudent;
import com.kaigejava.kgblog.model.auto.tStudentExample;
import com.kaigejava.kgblog.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private tStudentMapper studentMapper;
    @Override
    public PageInfo<tStudent> findAllStudent(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        tStudentExample example = new tStudentExample();
        List<tStudent> list = studentMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);
        return result;
    }

    @Override
    public int addStudent(tStudent student) {
        return studentMapper.insertSelective(student);
    }

    @Override
    public int updateById(tStudent student) {
        return studentMapper.updateByPrimaryKey(student);
    }

    @Override
    public tStudent getById(tStudent student) {
        return studentMapper.selectByPrimaryKey(student.getId());
    }
}
